package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.data.group.SpeechSection;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.util.group.SpeechSectionGroup;

/**
 * The type debateBodyType specifies a content model of the main hierarchy of a debate.
 * 
 * <pre>
 * 	<xsd:complexType name="debateBodyType">
 * 		<xsd:sequence minOccurs="1" maxOccurs="unbounded">
 * 			<xsd:group ref="speechSection"/>
 * 		</xsd:sequence>
 * 		<xsd:attributeGroup ref="coreopt"/>
 * 	</xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/2.0
 */
public abstract class DebateBodyType extends CoreOptImpl {

	// Mandatory (min 1).
	private final List<SpeechSection> _speechesSection = new ArrayList<SpeechSection>();

	public List<SpeechSection> getSpeechesSection() {
		return _speechesSection;
	}

	public void addSpeechSection(SpeechSection section) {
		_speechesSection.add(section);
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		super.writeExternal(out);
		for (int i = 0, n = _speechesSection.size(); i < n; i++) {
			_speechesSection.get(i).writeExternal(out);
		}
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		super.readExternal(in);
		SpeechSectionGroup.read(in, _speechesSection);
	}

}